/*
*    Phantom Test Driver v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ptd;

/**
 *
 * @author John
 */
public class PTDRemoteThread extends PTDScriptThread {
    PTDRemoteMachine myMachine;
    public void setMachine(PTDRemoteMachine Machine){
        myMachine = Machine;
    }
    
    public PTDRemoteThread(PTDScriptComm InComm, PTDDisplay InDisp, boolean bDoDisp){
        super(InComm, InDisp, bDoDisp);                
    }
    
    // -----------------------------------------------------
    public void run(){     
        if(PTDMain.bJavaClientInitialized == false){
            pW.displayFailure("Run unsuccessful - PTD initialization failed.");
            return;
        }
        
        String ExternalsPath = Main.getAppDir();
        
        RunState = THREAD_RUNNING;
        //if(RunType == TYPE_CONSOLE){
        //    runConsole(ExternalsPath);
        //}else{
        if(bDoDisplay){
            Disp.startScript(ScriptPath);
        }
        runID = getRemoteID();
        myMachine.CurrentThread = this;
        runRemoteScript(ScriptPath, Arguments, myMachine.myName, myMachine.myPort, 0, runID);
        myMachine.CurrentThread = null;
        
        if(bDoDisplay){
            Disp.stopScript();
        }
        CleanUp();
    }

    // -----------------------------------------------------
    public void CleanUp(){
        Main.debug_out("Stopping remote thread...");
        RunState = THREAD_STOPPED;
        //if(PTDMain.bJavaClientInitialized){
        //    killScript();
        //}else{
        //    pW.displayFailure("Error in JavaClient.dll - reinstall PTD");
        //}
        //pW.setRunState(0);
    }
    
    // -----------------------------------------------------
    public void Kill(){
        killRemoteScript(runID);
        myMachine.CurrentThread = null;
        myMachine.runState = false;
    }
    
    




    
}
